home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / prog / atari / c / btnc200 / config.c < prev    next >
C/C++ Source or Header  |  1996-09-10  |  7KB  |  304 lines

  1. /*
  2. **    Program:    BTNC
  3. **
  4. **    Module:        Configuration parser
  5. */
  6.  
  7. #include        <portab.h>
  8.  
  9. #include        <stdio.h>
  10. #include        <stdlib.h>
  11. #include        <ext.h>
  12. #include        <string.h>
  13. #include        <ctype.h>
  14.  
  15. #include        "general.h"
  16. #include        "globals.h"
  17. #include        "logfile.h"
  18.  
  19. /* Modified -------------- */
  20.  
  21. EXTERN BYTE    CopyrightMessage[];
  22.  
  23. /* ------------------------ */
  24.  
  25. MLOCAL struct ffblk        fileinfo;
  26.  
  27. VOID ProcessLine(BYTE *line, BYTE *s, BYTE *p1, BYTE *p2, BYTE *p3)
  28. {
  29.     BYTE    *pos,
  30.             *token;
  31.     
  32.     pos = strchr(line, ';');
  33.     if (pos) *pos = EOS;
  34.     
  35.     pos = strchr(line, '\n');
  36.     if (pos) *pos = EOS;
  37.     
  38.     token = strtok(line, " ");
  39.     
  40.     *s = *p1 = *p2 = *p3 = EOS;
  41.     
  42.     if (token)
  43.     {
  44.         strcpy(s, token);
  45.         strupr(s);
  46.         
  47.         token = strtok(NULL, " ");
  48.         
  49.         if (token)
  50.         {
  51.             strcpy(p1, token);
  52.             
  53.             token = strtok(NULL, " ");
  54.             
  55.             if (token)
  56.             {
  57.                 strcpy(p2, token);
  58.                 
  59.                 token = strtok(NULL, " ");
  60.                 
  61.                 if (token) strcpy(p3, token);
  62.             }
  63.         }
  64.     }
  65. }
  66.  
  67. WORD SearchValidList(BYTE *basename)
  68. {
  69.     BYTE    mask[13],
  70.             buffer[128];
  71.     BYTE    *ext;
  72.     BOOLEAN    found;
  73.     
  74.     strcpy(mask, basename);
  75.     strcat(mask, ".???");
  76.     
  77.     found = findfirst(mask, &fileinfo, 0x27);
  78.     
  79.     while (found == SUCCESS)
  80.     {
  81.         strcpy(buffer, fileinfo.ff_name);
  82.         
  83.         ext = strchr(buffer, '.') + 1L;
  84.         
  85.         if (isdigit(*ext) && isdigit(ext[1]) && isdigit(ext[2]))
  86.         {
  87.             strcpy(basename, strupr(fileinfo.ff_name));
  88.             return(SUCCESS);
  89.         }
  90.         
  91.         found = findnext(&fileinfo);
  92.     }
  93.     
  94.     return(FAILURE);
  95. }
  96.  
  97. VOID ParseConfig(WORD argc, BYTE **argv)
  98. {
  99.     BYTE        filename[128],
  100.                 line[256],
  101.                 statement[128],
  102.                 par1[128], par2[128], par3[128];
  103.     FILE        *cfgfile;
  104.     ADDRESS        addr;
  105.     DOMAINSPEC    *ndomain,
  106.                 *ldomain = NULL;
  107.     ADDLIST        *nadd,
  108.                 *ladd = NULL;
  109.     POINTLIST    *npl,
  110.                 *lpl = NULL;
  111.  
  112.     /*
  113.     ** Check for -c Flag on commandline
  114.     */
  115.     
  116.     if (argc > 1)
  117.     {
  118.         if (stricmp (argv[1], "-c") == 0)
  119.             c_format = TRUE;
  120.         else
  121.             ERR_printf("\nIllegal flag '%s' on commandline\n", argv[1]);
  122.     }
  123.             
  124.     strcpy(filename, "NODELIST.CFG");
  125.     
  126.     cfgfile = fopen(filename, "r");
  127.     
  128.     if (cfgfile == NULL)
  129.         ERR_printf("\nCouldn't read configuration file '%s', defaults are used.\n", filename);
  130.     else
  131.     {
  132.         while (fgets(line, 127, cfgfile) != NULL)
  133.         {
  134.             ProcessLine(line, statement, par1, par2, par3);
  135.             
  136. /* Modified -------------------------- */
  137.  
  138.             if (strcmp(statement, "LOGFILE") == SUCCESS)
  139.             {
  140.                 if (*par1 == EOS)
  141.                 {
  142.                     ERR_puts("\nMissing filename in 'Logfile' statement!\n");
  143.                     strcpy(logname,"BTNC.LOG");
  144.                 }
  145.                 else    strcpy(logname,par1);
  146.  
  147.                 logfile_open(logname);
  148.                 LOG_puts(&CopyrightMessage[1]);
  149.             #ifdef ALPHA
  150.                 LOG_puts(AlphaVersion);
  151.             #endif
  152.             #ifdef BETA
  153.                 LOG_puts(BetaVersion);
  154.             #endif
  155.                 write_logfile = TRUE;
  156.             }
  157.  
  158. /* ----------------------------------- */
  159.  
  160.             if (strcmp(statement, "MAKEUSERLIST") == SUCCESS)
  161.                 userlist = TRUE;
  162.             
  163.             if (strcmp(statement, "DISPLAY") == SUCCESS)
  164.                 display = TRUE;
  165.  
  166.             if (strcmp(statement, "STATISTICS") == SUCCESS)
  167.                 statistics = TRUE;
  168.             
  169.             if (strcmp(statement, "USERLISTNAME") == SUCCESS)
  170.             {
  171.                 if (*par1 == EOS)
  172.                     ERR_puts("\nMissing <userlistspec> parameter in 'UserlistName' statement!\n");
  173.                 else
  174.                     strcpy(userlist_name, par1);
  175.             }
  176.             
  177.             if (strcmp(statement, "POINTLIST") == SUCCESS)
  178.             {
  179.                 if (*par1 == EOS)
  180.                 {
  181.                     ERR_puts("\nMissing <file> parameter in 'PointList' statement!\n");
  182.                     ERR_puts("\nMissing <bossnode> parameter in 'PointList' statement!\n");
  183.                 }
  184.                 
  185.                 if (*par1 && *par2 == EOS)
  186.                     ERR_puts("\nMissing parameter in 'PointList' statement!\n");
  187.                 
  188.                 if (*par1 != EOS && *par2 != EOS)
  189.                 {
  190.                     if (findfirst(par1, &fileinfo, 0x27) == SUCCESS)
  191.                     {
  192.                         sscanf(par2, "%u:%u/%u.%u", &(addr.zone),
  193.                             &(addr.net), &(addr.node), &(addr.point));
  194.                         
  195.                         if (addr.point)
  196.                         {
  197.                             ERR_printf("\nFunny: You want add a pointlist to a point system (.%u)?\n", addr.point);
  198.                             ERR_puts("\nGood joke ! :-)  I'll treat it as if you meant his boss.\n");
  199.                             addr.point = 0;
  200.                         }
  201.                         
  202.                         if (strchr(par2, ':') == NULL || addr.net == 0 ||
  203.                             addr.zone == 0)
  204.                         {
  205.                             if (strchr(par2, ':') == NULL)
  206.                                 ERR_puts("\nInvalid <bossnode> address: zone missing. Pointlist not added.\n");
  207.                             else
  208.                             {
  209.                                 if (addr.zone == 0)
  210.                                     ERR_puts("\nInvalid <bossnode> address: zone can't be zero. Pointlist not added.\n");
  211.                                 if (addr.net == 0)
  212.                                     ERR_puts("\nInvalid <bossnode> address: net can't be zero. Pointlist not added.\n");
  213.                             }
  214.                         }
  215.                         else
  216.                         {
  217.                             npl = NewAtom(POINTLIST);
  218.                             
  219.                             npl->boss.zone = addr.zone;
  220.                             npl->boss.net = addr.net;
  221.                             npl->boss.node = addr.node;
  222.                             strcpy(npl->listfile, par1);
  223.                             
  224.                             if (pointlists == NULL)
  225.                                 pointlists = npl;
  226.                             if (lpl != NULL)
  227.                                 lpl->next = npl;
  228.                             
  229.                             lpl = npl;
  230.                         }
  231.                     }
  232.                     else
  233.                         ERR_printf("\nCouldn't find pointlist '%s'. Not added.\n", par1);
  234.                 }
  235.             }
  236.             
  237.             if (strcmp(statement, "DOMAIN") == SUCCESS)
  238.             {
  239.                 if (*par1 == EOS || *par2 == EOS)
  240.                     ERR_puts("\nMissing expected parameter(s) in 'Domain' statement!\n");
  241.                 else
  242.                 {
  243.                     strlwr(par1);
  244.                     
  245.                     ndomain = NewAtom(DOMAINSPEC);
  246.                     
  247.                     strcpy(ndomain->dat.name, par1);
  248.                     
  249.                     if (SearchValidList(par2) == SUCCESS)
  250.                     {
  251.                         strcpy(ndomain->dat.listfile, par2);
  252.                         
  253.                         if (*par3 != EOS)
  254.                             ndomain->dat.zone = atoi(par3);
  255.                         else
  256.                             ndomain->dat.zone = MULTIZONE;
  257.                     }
  258.                     else
  259.                         ERR_printf("\nCouldn't find a valid <%s> file! Domain ignored.\n", par2);
  260.                     
  261.                     if (domains == NULL) domains = ndomain;
  262.                     if (ldomain != NULL) ldomain->next = ndomain;
  263.                     
  264.                     ldomain = ndomain;
  265.                 }
  266.             }
  267.             
  268.             if (strcmp(statement, "ADDLIST") == SUCCESS)
  269.             {
  270.                 if (*par1 == EOS || *par2 == EOS)
  271.                     ERR_puts("\nMissing expected parameter(s) in 'AddList statement!\n");
  272.                 else
  273.                 {
  274.                     nadd = NewAtom(ADDLIST);
  275.                     
  276.                     strcpy(nadd->listfile, par1);
  277.                     sscanf(par2, "%u:%u", &nadd->tozone, &nadd->toregion);
  278.                     
  279.                     if (addlists == NULL) addlists = nadd;
  280.                     if (ladd != NULL) ladd->next = nadd;
  281.                     
  282.                     ladd = nadd;
  283.  
  284. /* Modified ------------------------- */
  285.  
  286.                     if (stricmp(par3, "4D") == SUCCESS)
  287.                     {
  288.                         nadd->dimension4=TRUE;
  289.                     }
  290.                     else if (stricmp(par3, "NF") == SUCCESS)
  291.                     {
  292.                         nadd->new_3D_format=TRUE; /* New German Format */
  293.                     }
  294.                     
  295. /* ---------------------------------- */
  296.  
  297.                 }
  298.             }
  299.         }
  300.         
  301.         fclose(cfgfile);
  302.     }
  303. }
  304.